<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>js01</title>
</head>

<body>

    <div id="d1"></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>

    <script>
        /* 
                   var div1 = document.getElementById('d1');
                   console.log(div1);
                   div1.innerHTML="大家好！";
         */
        var colors = ['#FFDDDD', '#DDFFDD', '#DDDDFF', '#DDDDDD', '#DDDFFF'];
       
        /* var arr = document.getElementsByTagName('div');
        for(var i=0;i<arr.length;i++){
             arr[i].innerHTML = i;
             arr[i].style.backgroundColor=colors[i%colors.length];
             arr[i].style.margin='20px';
        } */


        var k = 0;
        function showColor() {
            var arr = document.getElementsByTagName('div');
            for (var i = 0; i < arr.length; i++) {
                arr[i].innerHTML = i;
                arr[i].style.backgroundColor = colors[(i + k) % colors.length];
                arr[i].style.margin = '20px';
            }
            k++;

            setTimeout(showColor, 100);
        }

        showColor();


    </script>


</body>

</html>